﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>addUser</title>

    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-3.6.0.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script src="~/Scripts/vue.js"></script>
    <script src="~/Scripts/util.js"></script>
</head>
<body>
    <div style="text-align:center">
        <h2>添加用户</h2>
    </div>
    <form class="form-horizontal" action="javascript:">
        <div style="width: 500px; margin: 50px auto 0 auto">
            <div class="form-group">
                <label class="col-sm-2 control-label">用户名</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" name="sname">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">密码</label>
                <div class="col-sm-8">
                    <input type="password" class="form-control" name="password">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">状态</label>
                <div class="col-sm-8">
                    <select class="form-control" id="active">
                        <option selected value="1">活跃</option>
                        <option value="0">锁定</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">角色</label>
                <div class="col-sm-8">
                    <select class="form-control" id="role">
                        <option selected value="user">user</option>
                        <option value="admin">admin</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" />
                            Remember me
                        </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button class="btn btn-default" onclick="addUser()">提交</button>
                </div>
            </div>
        </div>
    </form>
    <script>
        function addUser() {
            var data = {
                "UserName": $("input[name='sname']").val(),
                "PassWord": $("input[name='password']").val(),
                "Active": $("#active").val(),
                "Role": $("#role").val()
            }
            $.ajax({
                url: "/Admin/AddUser",
                type: "post",
                data: data,
                success: function (data) {
                    if (data.status == 200) {
                        alert(data.msg);
                        location.href = "/Admin/Index";
                    } else {
                        alert(data.msg);
                    }
                }
            });
        }
    </script>
</body>
</html>
